package com.itheima;

import com.itheima.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;


/**
 * 容器初始化的而两种方式：
 * 1.通过加载类路径
 *      new ClassPathXmlApplicationContext("applicationContext.xml")
 * 2.通过绝对路径获取配置文件
 *      new FileSystemXmlApplicationContext("F:\\黑马Java学习路线\\SSM框架\\代码\\复习\\Spring\\spring_10_container\\src\\main\\resources\\applicationContext.xml");
 *路径里面可以写多个路径，以便加载多个配置文件
 *
 * 获取bean的两种方式：
 *
 *
 */
public class App {

    public static void main(String[] args) {

        //加载类路径下的配置文件
        ApplicationContext cx = new ClassPathXmlApplicationContext("applicationContext.xml");

        //绝对路径

        ApplicationContext cx1 = new FileSystemXmlApplicationContext("F:\\黑马Java学习路线\\SSM框架\\代码\\复习\\Spring\\spring_10_container\\src\\main\\resources\\applicationContext.xml");
        BookDao bookDao = (BookDao) cx.getBean("bookDao");

        //按名称获取
        BookDao bookDao1 = cx.getBean("bookDao" , BookDao.class);

        //按类型获取     -->必须唯一
        BookDao bookDao2 = cx.getBean(BookDao.class);

        bookDao.save();
    }
}
